package com.sunrise.gateway.web.servlet;

import com.sunrise.gateway.commons.CommonUtils;
import com.sunrise.gateway.commons.Result;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by wm on 2017/6/6
 */
public class ClearCookiesServlet extends ServletBase {
    @Override
    public void init() throws ServletException {
        super.init();
    }

    @Override
    protected void doMyPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        Session session = SecurityUtils.getSubject().getSession(false);
        if (session == null) {
            return;
        }

        final String sessionId = String.valueOf(session.getId());
        CommonUtils.clearCookies(req, resp);

        Result result = new Result(com.dap.commons.Constants.ResponseCode.SYS_SUCCESS, "", "\"" + sessionId + "\"");
        CommonUtils.writeStrIntoResponse(result.toJsonString(), resp);
    }



    @Override
    protected void doMyGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doMyPost(req, resp);
    }


}
